﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Platform.Migrations
{
    /// <inheritdoc />
    public partial class modify_table_AppModule : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_MainAppTopic_MainProductNamespace_ProductNamespaceId",
                table: "MainAppTopic");

            migrationBuilder.DropTable(
                name: "MainProductNamespace");

            migrationBuilder.RenameColumn(
                name: "ProductNamespaceId",
                table: "MainAppTopic",
                newName: "AppModuleId");

            migrationBuilder.RenameIndex(
                name: "IX_MainAppTopic_ProductNamespaceId",
                table: "MainAppTopic",
                newName: "IX_MainAppTopic_AppModuleId");

            migrationBuilder.CreateTable(
                name: "MainAppModule",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ApplicationId = table.Column<Guid>(type: "uuid", nullable: false),
                    ModuleCode = table.Column<string>(type: "text", nullable: false),
                    ModuleName = table.Column<string>(type: "text", nullable: false),
                    DefaultFlag = table.Column<bool>(type: "boolean", nullable: false),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    Exp = table.Column<string>(type: "text", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainAppModule", x => x.Id);
                });

            migrationBuilder.AddForeignKey(
                name: "FK_MainAppTopic_MainAppModule_AppModuleId",
                table: "MainAppTopic",
                column: "AppModuleId",
                principalTable: "MainAppModule",
                principalColumn: "Id");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_MainAppTopic_MainAppModule_AppModuleId",
                table: "MainAppTopic");

            migrationBuilder.DropTable(
                name: "MainAppModule");

            migrationBuilder.RenameColumn(
                name: "AppModuleId",
                table: "MainAppTopic",
                newName: "ProductNamespaceId");

            migrationBuilder.RenameIndex(
                name: "IX_MainAppTopic_AppModuleId",
                table: "MainAppTopic",
                newName: "IX_MainAppTopic_ProductNamespaceId");

            migrationBuilder.CreateTable(
                name: "MainProductNamespace",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    DefaultFlag = table.Column<bool>(type: "boolean", nullable: false),
                    Exp = table.Column<string>(type: "text", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true),
                    NamespaceCode = table.Column<string>(type: "text", nullable: false),
                    NamespaceName = table.Column<string>(type: "text", nullable: false),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainProductNamespace", x => x.Id);
                });

            migrationBuilder.AddForeignKey(
                name: "FK_MainAppTopic_MainProductNamespace_ProductNamespaceId",
                table: "MainAppTopic",
                column: "ProductNamespaceId",
                principalTable: "MainProductNamespace",
                principalColumn: "Id");
        }
    }
}
